<?php
namespace Admin\Controller;
/**
 * 通知/公告
 */
class NoticeController extends AdminController{
	/**
	 * 列表
	 * huying Dec 29, 2015
	 */
	public function index()
	{
		$where = '1 = 1';
		$list=$this->getList('*','notice',$where,'id desc',true);
		$this->assign('list', $list);
		$this->display();
	}
	/**
	 * 添加
	 * huying Dec 29, 2015
	 */
	public function add()
	{
		if(IS_POST)
		{
          $data=array(
				'title'       => $_POST['title'],
				'status'      => 1,
				'desc'        => $_POST['desc'],
				'sort'        => $_POST['sort'],
				'update_time' => time(),
				'add_time'    => time(),
				);
         $result = M('notice')->add($data);
         $this->returnResult($result);
		}else{
			$this->display();
		}

	}
	/**
	 * 修改
	 * huying Dec 29, 2015
	 */
	public function edit()
	{
		if(IS_POST)
		{
			$data=array(
				'title'       => $_POST['title'],
				'status'      => 1,
				'desc'        => $_POST['desc'],
				'sort'        => $_POST['sort'],
				'update_time' => time(),
				);
            $result=M('notice')->where('id='.$_POST['id'])->save($data);
			if($result)
			{
               $this->success('操作成功',U('Notice/index'));
			}else{
			$this->error('操作失败');
			}
		}else{
			$info = $this->getInfo('*', 'notice', 'id='.I('get.id', 0, 'intval'));
			$this->assign('info', $info);
			$this->display('add');
		}
	}
	/**
	 * 删除
	 * huying Dec 29, 2015
	 */
	public function del()
	{
		//$result = M('notice')->where('id='. I('get.id',0,'intval'))->setField('status',2);
		$result = $this->deleteData('id=' . I('get.id', 0, 'intval'), 'notice');
    	$this->returnResult ( $result );
	}
	/**
	 * 查看
	 * yaoyongli 2016/3/19
	 */
	public function desc()
	{
		$info =$this->getInfo('desc', 'notice', 'id='.$_POST["id"]);
		if(empty($info))
		{
			$this->ajaxReturn(array('status' => -1, 'info' => '获取信息失败'));
		}
		$this->ajaxReturn(array('status' => 1, 'info' => $info));
	}

}